package gandalf.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.servlet.http.HttpServletRequest;

@Entity
public class Vstopnica implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    private Dogodek dogodek;
    private BigDecimal cena;
    private int kolicina;
    private String vrsta;
    private String naziv;

    /**
     * Get the value of naziv
     *
     * @return the value of naziv
     */
    public String getNaziv() {
        return naziv;
    }

    /**
     * Set the value of naziv
     *
     * @param naziv new value of naziv
     */
    public void setNaziv(String naziv) {
        this.naziv = naziv;
    }

    /**
     * Get the value of vrsta
     *
     * @return the value of vrsta
     */
    public String getVrsta() {
        return vrsta.equals("default") ? "standardna" : vrsta;
    }

    /**
     * Set the value of vrsta
     *
     * @param vrsta new value of vrsta
     */
    public void setVrsta(String vrsta) {
        this.vrsta = vrsta;
    }

    /**
     * Get the value of kolicina
     *
     * @return the value of kolicina
     */
    public int getKolicina() {
        return kolicina;
    }

    /**
     * Set the value of kolicina
     *
     * @param kolicina new value of kolicina
     */
    public void setKolicina(int kolicina) {
        this.kolicina = kolicina;
    }

    /**
     * Get the value of cena
     *
     * @return the value of cena
     */
    public BigDecimal getCena() {
        return cena;
    }

    /**
     * Set the value of cena
     *
     * @param cena new value of cena
     */
    public void setCena(BigDecimal cena) {
        this.cena = cena;
    }

    /**
     * Get the value of dogodek
     *
     * @return the value of dogodek
     */
    public Dogodek getDogodek() {
        return dogodek;
    }

    /**
     * Set the value of dogodek
     *
     * @param dogodek new value of dogodek
     */
    public void setDogodek(Dogodek dogodek) {
        this.dogodek = dogodek;
    }

    /**
     * Get the value of id
     *
     * @return the value of id
     */
    public Long getId() {
        return id;
    }

    /**
     * Set the value of id
     *
     * @param id new value of id
     */
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "gandalf.model.Vstopnica[id=" + id + "]";
    }

    public List<Vstopnica> setAttributes(HttpServletRequest request, Dogodek dogodek) {
        List<Vstopnica> vstopnice = new ArrayList<Vstopnica>();

        int steviloVstopnic = Integer.parseInt(request.getParameter("steviloVstopnic"));

        Vstopnica v;
        String nazivVstopnica;
        BigDecimal cenaVstopnica;
        int kolicinaVstopnic;
        for (int i = 0; i < steviloVstopnic; i++) {
            v = new Vstopnica();
            nazivVstopnica = request.getParameter("naziv" + i);
            cenaVstopnica = new BigDecimal(request.getParameter("cena" + i));
            kolicinaVstopnic = Integer.parseInt(request.getParameter("kolicina" + i));

            v.setCena(cenaVstopnica);
            v.setKolicina(kolicinaVstopnic);
            v.setNaziv(dogodek.getNaziv());
            v.setVrsta(nazivVstopnica);
            v.setDogodek(dogodek);


            vstopnice.add(v);
        }

        return vstopnice;
    }
}
